<?php 
//$lang="KR";
//$company="elitech";
//$orderid="250";
//$username="abc";
$lang=$_REQUEST['lang'];
$company=$_REQUEST['company'];
$orderid=$_REQUEST['id'];
$username=$_REQUEST['username'];
$idemployees=$_REQUEST['idemployees'];

$temp = explode(";",$idemployees);
$connection = mysql_connect("1.234.53.52", "cam", "5678" ) ;
//$connection = mysql_connect("localhost", "root", "root" ) ;
mysql_select_db("elihan", $connection);
mysql_query("set names 'utf8'");
$selectdatabase = mysql_query("SELECT am.DatabaseName,am.Logo from ac_eli_manager am where am.KeyName='$company' and am.`Status` = 2");
$result = mysql_fetch_assoc($selectdatabase);
$db= $result['DatabaseName'];
echo $db;
mysql_select_db($db, $connection);


if (empty($lang) || $lang == "EN") {
	$value = "value/value_en.php";
} else if($lang == "VN") {
	$value = "value/value_vn.php";
}
else {
	$value = "value/value_kr.php";
}
include($value);
$result=mysql_query("SELECT * FROM or_order_tax o WHERE o.orderid='$orderid'");
while ($row = mysql_fetch_array($result))
{
	$ordertime = $row['order_time'];
	$cusname = $row['order_cusname'];
	$order_content = $row['order_content'];
	$order_suplly_rice = $row['order_supply_rice'];
	$order_tax = $row['order_tax'];
	$order_total = $row['order_total'];
	$order_time_transaction = $row['order_time_transaction'];
	if($order_time_transaction=="0000-00-00")
		$order_time_transaction="";
	$order_memo = $row['order_memo'];

}

// file 03-gmail.php
		
		//NhÃºng thÆ° viá»‡n phpmailer
		require_once('class.phpmailer.php');
		
		//Khá»Ÿi táº¡o Ä‘á»‘i tÆ°á»£ng
		$mail = new PHPMailer();
		
		$mail->IsSMTP(); // Gá»�i Ä‘áº¿n class xá»­ lÃ½ SMTP
		//$mail->Host       = "mail.zend.vn"; // tÃªn SMTP server
		$mail->SMTPDebug  = 2;                    // enables SMTP debug information (for testing)
		                                           // 1 = errors and messages
		                                           // 2 = messages only
		$mail->SMTPAuth   = true;                  // Sá»­ dá»¥ng Ä‘Äƒng nháº­p vÃ o account
		$mail->SMTPSecure = "ssl";
		$mail->Host       = "smtp.gmail.com";     // Thiáº¿t láº­p thÃ´ng tin cá»§a SMPT
		$mail->Port       = 465;                     // Thiáº¿t láº­p cá»•ng gá»­i email cá»§a mÃ¡y
		$mail->Username   = "elisoftmailserver@gmail.com"; // SMTP account username
		$mail->Password   = "1234567892727";         // SMTP account password
		
		//Thiet lap thong tin nguoi gui va email nguoi gui
		//$yesterday=date("Y-m-d", time() - 86400);
		$mail->SetFrom('elisoftmailserver@gmail.com',$company.' - Order');
		
		//Thiáº¿t láº­p thÃ´ng tin ngÆ°á»�i nháº­n
		//$mail->AddAddress("klkim169@gmail.com", "klkim");
		
		$temp = explode(";",$idemployees);
		$sql="SELECT e.Email,e.FullName FROM employee e WHERE ";
		for ($i=0;$i<count($temp)-1;$i++){
			$sql.="e.IDEmployee='".$temp[$i]."' OR ";
		}
		$sql.="e.IDEmployee='".$temp[$i]."'";
		$q=mysql_query($sql);
		while ($row=mysql_fetch_array($q)){
			$mail->AddAddress($row['Email'], $row['FullName']);
		}
		
		$mail->Subject    =  $company.' - Order';
		
		$mail->CharSet = "utf-8";
		$mail->IsHTML(true);
	
		
		$body='';
		$body.='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
				<html xmlns="http://www.w3.org/1999/xhtml">
				<head>
				<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
				<title>Untitled Document</title>
				</head>
				
				<body>
				<table class="ftable" width="100%" cellspacing="1" cellpadding="0" border="0">
				<tbody>
				 <tr height="40px">
	                <th style="width: 10%;min-width: 100px;background: #4f81bd;height: 30px;color: white;font-size: 16px;font-weight: bold;">'.$l_ngaythangnam.'</th>
	                <th style="width: 18%;min-width: 170px;background: #4f81bd;height: 30px;color: white;font-size: 16px;font-weight: bold;">'.$l_company_name.'</th>
	                <th style="width: 35%;min-width: 220px;background: #4f81bd;height: 30px;color: white;font-size: 16px;font-weight: bold;">'.$l_product_item.'</th>
	                
	                <th style="width: 8%;min-width: 80px;background: #4f81bd;height: 30px;color: white;font-size: 16px;font-weight: bold;">'.$l_Supply_price.'</th>
	                <th style="width: 8%;min-width: 80px;background: #4f81bd;height: 30px;color: white;font-size: 16px;font-weight: bold;">'.$l_vat.'</th>
	                <th style="width: 8%;min-width: 80px;background: #4f81bd;height: 30px;color: white;font-size: 16px;font-weight: bold;">'.$l_amount.'</th>
	                <th style="width: 10%;min-width: 100px;background: #4f81bd;height: 30px;color: white;font-size: 16px;font-weight: bold;">'.$thoigiangiaodich.'</th>
	                <th style="width: 10%;min-width: 120px;background: #4f81bd;height: 30px;color: white;font-size: 16px;font-weight: bold;">'.$l_memo.'</th>
	            </tr>
				<tr style="background: #d0d8e8;" height="40px">
					                <td style="font-size: 16px;text-align: center;">'.$ordertime.'</td>
					                <td style="text-align:left;font-size: 16px;">'.$cusname.'</td>
					                <td style="text-align:left;font-size: 16px;">'.$order_content.'</td>
					                <td style="text-align:right;font-size: 16px;">'.number_format($order_suplly_rice).'</td>
					                <td style="text-align:right;font-size: 16px;">'.number_format($order_tax).'</td>
					                <td style="text-align:right;font-size: 16px;">'.number_format($order_total).'</td>
					                <td style="font-size: 16px;text-align: center;">'.$order_time_transaction.'</td>
					                <td style="font-size: 16px;text-align: center;">'.$order_memo.'</td>
				</tr>
				</tbody>
				</table>
				</body>
				</html>';


$body .='<br><table width="100%" style="padding:20px" >
	<tr><td align="right"><b>'.$l_sender.':</b> <b><i>'.$username.'</i></b></td></tr>
	</table>';
	
//echo $body;
$mail->Body = $body;
	
if(!$mail->Send()) {
  	echo "Mailer Error: " . $mail->ErrorInfo;
} else {
 	echo "Sent Successfully";
}
 mysql_close($connection);
 
 ?>